package com.wzapp.sitposture.usercenter.repository;

import com.wzapp.sitposture.usercenter.entity.UserSettingPosture;
import com.wzapp.sitposture.usercenter.view.SettingPostureDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

/**
 * 功能: 姿态信息<br/>
 *
 * @author qianglong
 * @version 1.1
 * @create 2019-01-27 16:31
 **/
@RepositoryRestResource
public interface UserSettingPostureRepository extends JpaRepository<UserSettingPosture, String> {

    Page<UserSettingPosture> findByUserIdAndUploadTimeGreaterThanEqual(String userId,Long uploadTime, Pageable pageable);

    @Query(value = "SELECT t.type,sum(t.duration) as durationTime FROM user_setting_posture t where t.user_id=?1 and DATE(t.upload_time)= ?2 group by t.type order by t.type",nativeQuery = true)
    List<Object[]> findByUserIdAndUploadTime(String userId,String uploadTime);
}
